<template>
  <div class="city-group-item">
    <van-index-bar :sticky="false" :index-list="indexList">
      <van-index-anchor index="热门" />
      <div class="list">
        <template v-for="(hotCity,index) in groupData.hotCities" :key="index">
          <div class="city" @click="cityClick(hotCity)">{{ hotCity.cityName }}</div>
        </template>
      </div>
      <template v-for="(group,index) in groupData.cities" :key="index">
        <van-index-anchor :index="group.group" />
        <template v-for="(city,indey) in group.cities" :key="indey">
          <van-cell :title="city.cityName" @click="cityClick(city)" />
        </template>
      </template>
    </van-index-bar>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import useCityStore from '@/stores/modules/city.js'
import router from '@/router'
const props = defineProps({
  groupData: {
    type: Object,
    default: () => ({})
  }
})

const indexList = computed(() => {
  const list = props.groupData.cities.map(item => item.group)
  list.unshift("#")
  return list
})

const cityStore = useCityStore()

const cityClick = (city) => {
  cityStore.currentCity = city
  router.back()
}

</script>

<style lang="less" scoped>
.list {
  display: flex;
  justify-content: space-around;
  padding: 20px;
  padding-right: 50px;
  flex-wrap: wrap;

  .city {
    width: 140px;
    height: 56px;
    border-radius: 28px;
    font-size: 24px;
    color: #000;
    text-align: center;
    line-height: 56px;
    background-color: #fff4ec;
    margin-bottom: 20px;
  }
}
</style>